package com.yunji.framework_template.books.web.controller;
import com.yunji.framework_template.books.orm.persistence.model.BooksComment;
import com.yunji.framework_template.books.biz.service.BooksCommentService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.common.web.Page;

import java.util.List;

import org.apache.ibatis.annotations.Param;

/**
 *
 * Created by fenglibin on 2019/01/24.
 */
@Controller
@RequestMapping("/booksComment/")
public class BooksCommentController {

    @Autowired
    BooksCommentService booksCommentService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<BooksComment>> selectAll(){
        return Result.success(booksCommentService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<BooksComment> selectByPrimaryKey(Integer id){
        return Result.success(booksCommentService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<BooksComment>> selectByCondition(BooksComment record){
        return Result.success(booksCommentService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(BooksComment record){
        return Result.success(booksCommentService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(BooksComment record){
        return Result.success(booksCommentService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(BooksComment record){
        return Result.success(booksCommentService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<BooksComment>>> selectByPage(Page<BooksComment> page){
        List<BooksComment> list = null;
        page = page.sequentialDisplayCalculate(booksCommentService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = booksCommentService.selectByPage(page);
        }
        Page<List<BooksComment>> result = new Page<List<BooksComment>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition")
    @ResponseBody
    public Result<Integer> deleteByCondition(BooksComment record){
        return Result.success(booksCommentService.deleteByCondition(record));
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id){
        return Result.success(booksCommentService.deleteByPrimaryKey(id));
    }

}
